from core.config.mongodb_config import MonGoDBBuilder

class MonGoDBClient:
    def __init__(self):
        self.client = MonGoDBBuilder.get_mongo_client()

    def connect(self, db_name, collection_name):
        db = self.client[db_name]
        collection = db[collection_name]
        return collection

    def disconnect(self):
        self.client.close()

# 创建全局的 MonGoDBClient 变量
global_mongo_client = MonGoDBClient()

if __name__ == '__main__':
    MonGoDBClient = global_mongo_client
    coll = MonGoDBClient.connect("scrapy_crawl_news", "news_list")
    print(coll.find_one())